// 引入axios
import axios from "axios";
// 设置公共接口
axios.defaults.baseURL = '/api/xiaochengxu';
// 设置请求超时时间
axios.defaults.timeout = 5000;

// 请求拦截器
axios.interceptors.request.use( config => {
  return config;
}, error => {
  return Promise.reject(error);
} )

// 响应拦截器
axios.interceptors.response.use( response => {
  return response.data;
}, error => {
  return Promise.reject(error);
} )

// 导出get请求
export const get = ( url, data = {} ) => {
  return new Promise( ( resolve, reject ) => {
    axios.get( url, { params: data } ).then( res => {
      resolve( res );
    }, err => {
      reject( err );
    })
  })
}

// 导出post请求
export const post = ( url, data) => {
  return new Promise( ( resolve, reject ) => {
    axios.post( url,data ).then( res => {
      resolve( res );
    }, err => {
      reject( err );
    })
  })
}